package com.xiaoyu.lanling.feature.chat.viewholder

import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.emoji.widget.EmojiTextView
import com.facebook.drawee.view.SimpleDraweeView
import com.xiaoyu.base.utils.extensions.isSystemAccount
import com.xiaoyu.lanling.R
import com.xiaoyu.lanling.feature.chat.model.message.ChatMessageReceiveTextItem
import com.xiaoyu.lanling.media.image.ImageViewUtil
import com.xiaoyu.lanling.widget.textview.LinkEmojiTextView

class ChatMessageReceiveTextViewHolder : ChatMessageBaseReceiveSendViewHolder<ChatMessageReceiveTextItem>() {

    private var mText: LinkEmojiTextView? = null
    private var mRewardLayout: View? = null
    private var mRewardIcon: SimpleDraweeView? = null
    private var mRewardDesc: EmojiTextView? = null

    override fun doCreateChildrenView(layoutInflater: LayoutInflater, parent: ViewGroup): View {
        val view = layoutInflater.inflate(R.layout.item_chat_receive_text, parent, false)
        mText = view.findViewById(R.id.chat_message_text)
        mRewardLayout = view.findViewById(R.id.reward_layout)
        mRewardIcon = view.findViewById(R.id.reward_icon)
        mRewardDesc = view.findViewById(R.id.reward_desc)
        return view
    }

    override fun showData(position: Int, itemData: ChatMessageReceiveTextItem) {
        super.showData(position, itemData)
        mRewardLayout?.visibility = if (TextUtils.isEmpty(itemData.rewardInfo.desc)) View.GONE else View.VISIBLE
        mRewardDesc?.text = itemData.rewardInfo.desc
        mRewardDesc?.setTextColor(itemData.rewardInfo.textColor)
        ImageViewUtil.loadImage(mRewardIcon, itemData.rewardInfo.iconloadParam)

        if (itemData.singleChat) {
            mUserDisplayName?.visibility = View.GONE
        } else {
            mUserDisplayName?.visibility = View.VISIBLE
            mUserDisplayName?.text = itemData.displayName
        }
        mText?.text = itemData.text
        mText?.enableClickForLink = itemData.user.isSystemAccount()
    }
}